<template>
  <Panel v-loading="loading">
    <template #title>
      <el-button
        type="primary"
        icon="el-icon-upload2"
        size="small"
        @click="handleDownload"
        >导出PDF</el-button
      >
    </template>
    <div class="resume-detail">
      <Basic :data="detailData.personInfo" />
      <Training :data="detailData.practiceTrainings" />
      <Experience :data="detailData.workExperiences" />
      <Education :data="detailData.educations" />
      <Skill :data="detailData.skills" />
      <Evaluation :data="detailData.selfEvaluation" />
    </div>
    <div class="text-center">
      <el-button size="small" type="primary" @click="employResume(true)"
        >录用</el-button
      >
      <el-button size="small" type="info" @click="employResume(false)"
        >不适用</el-button
      >
    </div>
  </Panel>
</template>

<script>
import Basic from './Basic'
import Training from './Training'
import Experience from './Experience'
import Education from './Education'
import Skill from './Skill'
import Evaluation from './Evaluation'
import { Panel } from 'components'
import {
  getResumeDetail,
  downloadResume,
  employResume
} from 'services/company/job'
export default {
  name: 'ResumeDetail',
  components: {
    Panel,
    Basic,
    Training,
    Experience,
    Education,
    Skill,
    Evaluation
  },
  data() {
    return {
      detailData: {},
      services: {
        detail: getResumeDetail
      }
    }
  },
  methods: {
    async getDetailData() {
      try {
        this.loading = true
        const postId = this.$route.params.id
        const { data } = await this.services.detail({ postId })
        this.detailData = data
      } finally {
        this.loading = false
      }
    },
    async handleDownload() {
      try {
        const postId = this.$route.params.id
        await downloadResume({ postId })
      } catch {}
    },
    async employResume(status) {
      try {
        await this.$confirm(
          '您确定要' + (status ? '录用' : '不录用') + '该简历？',
          this.$t('tip.systemTip'),
          {
            type: 'warning'
          }
        )
        const postId = this.$route.params.id
        const employStatus = status ? 2 : 3
        await employResume({ postId, employStatus })
      } catch {}
    }
  },
  created() {
    this.getDetailData()
  }
}
</script>

<style lang="scss">
@import 'styles/common.scss';
.resume-detail {
  padding: 0.5rem 0.2rem;
  .info-group {
    padding: 0.2rem 0.2rem;
    border-top: 1px solid $colorBorder3;
  }
}
</style>
